<template>
	<view>
		<personal v-if="!type" @toggle="type = 1"></personal>
		<enterprise v-if="type" @toggle="type = 0" :company="company"></enterprise>

		<!-- 搜索 -->
		<view class="padding-sm padding-bottom bg-white">
			<search @onClick="search"></search>
		</view>
		
		<u-gap height="8"></u-gap>
		<view class="cell padding-lr" @click="$goto('/pages/cards/recent')">
			最近添加
		</view>
		
		<!-- 排序 -->
		<!-- <view class="bg-white">
			<u-dropdown>
				<u-dropdown-item v-model="filterValue1" title="排序方式" :options="filter1"></u-dropdown-item>
			</u-dropdown>
		</view> -->

		<view class="cards" v-for="(group, key) in list" :key="key">
			<view class="gap">{{key}}</view>
			<card :avatar="i.portrait" :name="i.name" :job="i.position" :company="i.company" v-for="i in group" :key="i.id"
			 @click="$goto('/pages/cards/detail?type=check&id=' + i.id)"></card>
		</view>
	</view>
</template>

<script>
	import search from './components/search.vue'
	import card from './components/card.vue'
	import personal from './components/personal.vue'
	import enterprise from './components/enterprise.vue'
	export default {
		components: {
			search,
			card,
			personal,
			enterprise
		},
		data() {
			return {
				type: 0,
				typeList: ['personal', 'enterprise'],
				company: [],
				list: [],
				filterValue1: 1,
				filter1: [
					{
						label: '默认排序',
						value: 1
					},
					{
						label: '根据职位',
						value: 2
					},
					{
						label: '根据公司',
						value: 3
					}
				]
			};
		},
		onLoad() {

		},
		onShow() {
			this.getList()
			this.setTitle()
		},
		onPullDownRefresh() {
			this.getList()
		},
		watch: {
			type() {
				this.setTitle()
			}
		},
		methods: {
			async getList() {
				let { company, list } = await this.$u.api.getPersonlCards()
				this.company = company
				this.list = list
				uni.stopPullDownRefresh()
			},
			setTitle() {
				let title = this.type ? '企业' : '个人'
				uni.setNavigationBarTitle({
					title: title
				})
			},
			async search(e) {
				let res = await this.$u.get('/myvcard/friend/search?keywords=' + e)
				let {
					list
				} = res.data.result
				this.list = list
			}
		}
	}
</script>

<style lang="scss" scoped>
	/deep/ .toggle-btn {
		width: 180rpx;
		height: 56rpx;
		border-radius: 10rpx;
		display: flex;
		justify-content: space-around;
		align-items: center;
		font-size: 24rpx;
		margin: 0;

		&.personal {
			background: #eee;
			box-shadow: none;
			color: #000033;
		}
		
		&.enterprise {
			background: #626262;
			box-shadow: 0rpx 3rpx 7rpx 0rpx rgba(0, 0, 0, 0.21);
			color: #E1A55E;
		}
	}
	
	.cell {
		width: 100%;
		height: 90rpx;
		background: #fff;
		border-bottom: 1px solid rgba(0, 0, 0, 0.05);
		display: flex;
		align-items: center;
		font-size: 30rpx;
		letter-spacing: 1px;
		color: #333333;
	}

	.cards {
		.gap {
			padding: 22rpx;
			font-size: 26rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #95969F;
		}
	}
	
	/deep/ .u-dropdown__menu__item {
		justify-content: flex-start !important;
		padding: 0 40rpx;
	}
</style>
